package main

import (
	"fmt"
	"gin_demo/app/auth"
	"gin_demo/app/book"
	"gin_demo/app/user"
	"gin_demo/config"
	"gin_demo/middleware"
	"gin_demo/routers"
	"gin_demo/validator"
	"github.com/gin-gonic/gin"
)

func main() {
	// load config.json file
	if err := config.Init("./config.json"); err != nil {
		panic(err)
	}

	// init logger config
	if err := middleware.InitLogger(config.Conf.LogConfig); err != nil {
		fmt.Printf("init logger failed, err:%v\n", err)
		return
	}

	// init trans
	if err := validator.InitTrans("zh"); err != nil {
		fmt.Printf("init trans failed, err:%v\n", err)
		return
	}

	// init routers
	routers.Include(book.Routers, user.Routers, auth.Routers)
	r := routers.Init()

	// test cookie
	r.GET("/cookie", func(c *gin.Context) {
		cookie, err := c.Cookie("gin")
		if err != nil {
			cookie = "Not"
			c.SetCookie("gin", "test", 3600, "/", "localhost", false, true)
		}
		fmt.Printf("cookie: %s\n", cookie)
	})

	if err := r.Run(":8000"); err != nil {

	}
}
